/*
  ! 如果没有天赋，那就一直重复
  ! Created: 2024/06/04 08:40:42
*/
#include <bits/stdc++.h>
using namespace std;

#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)

const int N = 1e5 + 10;

using PII = pair<int, int>;

int n, ans;
vector<int> to[N];
multiset<PII> q[N];

inline void mer(int x, int y) {
  if (q[x].size() > q[y].size()) swap(q[x], q[y]);
  for (auto i : q[x]) q[y].insert(i); q[x].clear();
}
inline PII operator+(PII a, PII b) {
  return {a.first + b.first, a.second | b.second};
}
inline PII operator+(PII a, int b) {
  return {a.first + b, a.second};
}
inline int get(PII a) { return a.first + a.second; }
inline void dfs(int now, int fa) {
  for (auto i : to[now]) {
    if (i == fa) continue;
    dfs(i, now);
    mer(i, now);
  }
  if (now == 1) {
    if (q[now].size() == 0) ans = 1;
    if (q[now].size() == 1) ans = get(*q[now].begin()) + 1;
    if (q[now].size() >= 2) {
      auto it1 = prev(q[now].end());
      auto it2 = prev(it1);
      ans = get(*it1 + *it2) + 1;
    }
  } else {
    if (q[now].size() == 0) q[now].emplace(1, 0);
    else if (q[now].size() == 1) {
      int x, y; tie(x, y) = *q[now].begin();
      if (y == 1) q[now].emplace(x + 2, 0);
      if (y == 0) q[now].emplace(x, 1);
      q[now].erase(q[now].begin());
    }
    else if (q[now].size() >= 2) {
      auto it1 = prev(q[now].end());
      auto it2 = prev(it1);
      if (it1->second && it2->second)
        q[now].emplace(1, 0);
      q[now].insert(*it1 + *it2 + 1);
      q[now].erase(it1);
      q[now].erase(it2);
    }
  }
}

signed main() {
  freopen("bird.in", "r", stdin);
  freopen("bird.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  fro(i, 1, n - 1) {
    int x, y;
    cin >> x >> y;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans << "\n";
  return 0;
}